<template>
	<uni-search-bar @confirm="toSearch" placeholder="请输入搜索的公交地铁线路" v-model="searchkey"></uni-search-bar>
	<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item style="height: 200px;" v-for="(item,index) in lunboList" :key="index">
			<view class="swiper-item">
				<image style="width: 100%;" :src="item.url" mode=""></image>
			</view>
		</swiper-item>
	</swiper>
	<!-- 天气 -->
	<view class="weather" style="height: 100rpx;border: 1px solid #ccc;margin: 5px;
	 border-radius: 5px;display: flex;justify-content: space-between; padding: 10rpx;align-items: center;">
		<view class="icon" style="width: 100rpx;height: 100rpx; ">
			<image style="width: 100%;height: 100%;" :src="'/static/weather/icons/'+ weatherNow.icon +'.svg'" mode="">
			</image>
		</view>
		<view class="text" style="font-size: 50rpx;margin-left: 10px;">
			{{weatherNow.temp}}°C
		</view>
		<view class="text" style="font-size: 34rpx;margin-left: 10rpx;">
			{{weatherNow.text}}
		</view>
		<view class="text" style=" margin-left: 10rpx;">
			{{weatherNow.windDir}} {{weatherNow.windScale}}级
		</view>
		<view>
			<view class="text" style="margin-left: 10rpx;">
				体感温度： {{weatherNow.feelsLike }}°C
			</view>
			<view class="text" style="margin-left: 10rpx;">
				湿度： {{weatherNow.humidity }}%
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import {
		CONFIG
	} from "../../utils/config.js"
	onLoad(() => {
		getlunbo()
		getWeather()
		getCurrentPos()
	})

	const searchkey = ref("")
	const lunboList = ref([])

	function toSearch() {
		// console.log("search")
		if (searchkey.value == "") {
			uni.showToast({
				title: "请输入查询的公交地图线路",
				icon: "none"
			})
		} else {
			window.location.href =
				`https://uri.amap.com/line?name=${searchkey.value}&city=029&callnative=0`
		}
	}


	let weatherNow = ref({})
	async function getWeather() {
		let res = await uni.$get(CONFIG.hefeng_now, {
			key: CONFIG.hefeng_key,
			location: CONFIG.hefeng_location
		})
		console.log("lunbo：" + res.data.code)
		if (res.data.code === "200") {
			weatherNow.value = res.data.now
		}
	}


	onLoad(() => {
		getlunbo()
		getCurrentPos()
	})

	async function getlunbo() {
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/lunbo")
		if (res.statusCode == 200) {
			lunboList.value = res.data.results
		}
		console.log(lunboList.value)
	}

	function getCurrentPos() {
		uni.getLocation({
			success: function(res) {
				console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);
			}
		})
	}
</script>

<style>

</style>